package com.qf.smsplatform.webmaster.controller;

import com.github.pagehelper.PageInfo;
import com.qf.smsplatform.webmaster.annotations.LogOperationAnno;
import com.qf.smsplatform.webmaster.dto.R;
import com.qf.smsplatform.webmaster.pojo.TNotify;
import com.qf.smsplatform.webmaster.service.NotifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/notify")
@Api(tags = "更新开关管理")
public class NotifyController {

    private NotifyService notifyService;

    @Autowired
    public void setNotifyService(NotifyService notifyService){
        this.notifyService = notifyService;
    }

    @PostMapping("/notity")
    @ApiOperation("修改开关")
    @LogOperationAnno("修改开关")//添加
    public R updateNotity(@RequestBody TNotify tNotify) {
        notifyService.updateNotify(tNotify);
        return R.setOk();
    }

    @PostMapping("/notitys")
    @ApiOperation("添加开关")
    @LogOperationAnno("添加开关")//添加
    public R addDirtyword(@RequestBody TNotify notify) {
        notifyService.add(notify);
        return R.setOk();
    }

    @GetMapping("/showAll")
    @ApiOperation("查询所有限流管理")
    @LogOperationAnno("查询所有限流管理")//查所有
    public R showTLimit(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        PageInfo<TNotify> pageInfo = notifyService.showAll(pageNum, pageSize);
        return R.setOk(pageInfo);
    }


    @DeleteMapping("/notity")
    @ApiOperation("删除开关")
    @LogOperationAnno("删除开关")
    public R delete(@RequestBody Map map) {
        notifyService.delete((List<Long>) map.get("id"));
        return R.setOk();
    }
}
